﻿using Abp.Quartz;
using Quartz;
using System.Threading.Tasks;

namespace Choucius.Boilerplate9.JobServices
{
    public class JobService
    {
        private readonly IQuartzScheduleJobManager _quartzScheduleJobManager;

        public JobService(IQuartzScheduleJobManager quartzScheduleJobManager)
        {
            _quartzScheduleJobManager = quartzScheduleJobManager;
        }

        public async Task ScheduleJob()
        {
            await _quartzScheduleJobManager.ScheduleAsync<DataPolling>(
            job =>
            {
                job.WithIdentity("MyLogJobIdentity", "MyGroup")
                    .WithDescription("A job to simply write logs.");
            },
            trigger =>
            {
                trigger.StartNow()
                    .WithSimpleSchedule(schedule =>
                    {
                        schedule.RepeatForever()
                            .WithIntervalInHours(12) // 每隔12小时同步一次
                            .Build();
                    });
            });
        }
    }
}
